package com.jy.rhin.infra.repo.audit;

import com.jy.common.UIDWorker;
import com.jy.rhin.domain.audit.AuditInfoDao;
import com.jy.rhin.domain.audit.entity.AuditInfo;
import com.jy.rhin.infra.repo.audit.mapper.AuditInfoMapper;
import com.jy.rhin.infra.repo.audit.po.AuditEventInfoPO;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;

/**
 * @author dhl
 * @date 2022/5/20
 * @Description
 */
@Service
public class AuditInfoDaoImpl implements AuditInfoDao {

    @Resource
    UIDWorker uidWorker;
    @Resource
    private AuditInfoMapper auditInfoMapper;

    @Override
    public AuditInfo getById(Long id) {
        AuditEventInfoPO po = auditInfoMapper.selectById(id);
        if(ObjectUtils.isEmpty(po)){
            return null;
        }
        return po.toDO();
    }

    @Override
    public Long save(AuditInfo info) {
        long id = uidWorker.nextId();
        AuditEventInfoPO po = new AuditEventInfoPO(id, info);
        auditInfoMapper.insert(po);
        return id;
    }

}
